import React from "react";
import { Route, Redirect } from 'react-router-dom';
import {message} from 'antd';
import getCookie from "../utils/getCookie";


const FilterRoute = ({component: Component, ...props}) => {
    // 解构赋值 将 props 里面的 component 赋值给 Component
    return <Route {...props} render={(p) => {
        let cookie=getCookie();
        if (cookie){ // 如果登录了, 返回正确的路由
            return <Component />
        } else { // 没有登录就重定向至登录页面
            return <Redirect to={{
                pathname: '/user/login',
                state: {
                    from: p.location.pathname
                }
            }}/>
        }
    }}/>
}
export default FilterRoute;